<?php
/* MyMeeting is an online meeting management software.
 * Copyright (C) 2009 Government Of Malaysia
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author: Abdullah Zainul Abidin, Nuhaa All Bakry
 *          Eavay Javay Barnad, Sarogini Muniyandi
 *
 */

class Committeetodo extends AppModel {

    /**
     * Defining the name of model
     *
     */
    var $name = 'Committeetodo';
    /**
     * Defining the name of the table
     *
     */
    var $useTable = 'committeetodos';
    /**
     * Defining behavior in the model
     *
     */
    var $actsAs = array();


    /**
     * Validating the fields in committeestodo model
     *
     */
    var $validate = array(
        'name'=>array(
            'required'=>array(
                'rule' => 'notEmpty'
            )
    ));

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    /**
     * A committee can see its committeetodo and an association is defined so that committeetodo can see its committee.
     *
     */
    var $belongsTo = array(
        'Committee' => array(
            'className' => 'Committee',
            'foreignKey' => 'committee_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
    );
    
    function saveTodo($user_id,$committee_id){
        
        if(!isset($this->Systemtodo)){
            App::import('Model','Systemtodo');
            $this->Systemtodo=& ClassRegistry::init('Systemtodo');
        }
        $todos=$this->Systemtodo->find('all',array('contain'=>false));
        foreach($todos as $todo){
            $ctodo['name']=$todo['Systemtodo']['name'];
            $ctodo['priority']=$todo['Systemtodo']['priority'];
            $ctodo['committee_id']=$committee_id;
            $ctodo['user_id']=$this->Auth->user('id');
            $this->create();
            $this->save($ctodo);
        }
    }

}
?>
